<template>
  <el-container>
    <el-header>
      <i class="el-icon-arrow-left" @click="goBack"></i>
      {{this.header}}
    </el-header>
    <el-main>
      <router-view></router-view>
    </el-main>
  </el-container>
</template>

<script>
  export default {
    name: "rm-main",
    data(){
      return{
        header: 'management'
      }
    },
    beforeRouteUpdate(to, from, next) {//当路由发生变化时执行
      this.header=to.name;
      next();
    },
    methods:{
      goBack () {
        if(this.header==='management'){
          this.$router.push({name: 'Home'})
        }else {
          window.history.length > 1
            ? this.$router.go(-1)
            : this.$router.push('/')
        }
      }
    }
  }
</script>

<style scoped>
  .el-header {
    background-color: #92b8f9;
    color: #ffffff;
    text-align: center;
    line-height: 60px;
    position: relative;
  }

  .el-icon-arrow-left {
    position: absolute;
    left: 5%;
    top: 35%;
  }
</style>
